IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'spBoxes_RetrieveAll')
	BEGIN
		PRINT 'Dropping Procedure spBoxes_RetrieveAll'
		DROP  Procedure  spBoxes_RetrieveAll
	END

GO

PRINT 'Creating Procedure spBoxes_RetrieveAll'
GO

CREATE Procedure spBoxes_RetrieveAll
	(
		@BoxNo varchar(50) = null, 
		@BoxStatus varchar(50) = null, 
		@BoxLocation varchar(50) = null, 
		@BoxWarehouse varchar(50) = null, 
		@LastTransactionUser_ID numeric(9,0) = null, 
		@LastTransactionDate DateTime = null
	)
AS
    /* 
    ------------------------------------------------------------------------------
    - Change History
    - --------------
    - Date          Description
    ------------------------------------------------------------------------------
    - 2007/11/02	Initial version created
    ------------------------------------------------------------------------------
    */
	
	SET NOCOUNT ON
	
	-- Retrieve the relevant records
	SELECT  *
	FROM	Boxes
	
	WHERE	(@BoxNo IS NULL OR Boxes.BoxNo LIKE @BoxNo + '%')
	  AND	(@BoxStatus IS NULL OR Boxes.BoxStatus LIKE @BoxStatus + '%')
	  AND	(@BoxLocation IS NULL OR Boxes.BoxLocation LIKE @BoxLocation + '%')
	  AND	(@BoxWarehouse IS NULL OR Boxes.BoxWarehouse LIKE @BoxWarehouse + '%')
	  AND	(@LastTransactionUser_ID IS NULL OR Boxes.LastTransactionUser_ID = @LastTransactionUser_ID)
	  AND	(@LastTransactionDate IS NULL OR Boxes.LastTransactionDate = @LastTransactionDate)

	-- Return to calling method
	RETURN
GO
